<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="红包类型" prop="type">
        <el-select
          v-model="queryParams.type"
          placeholder="请选择"
          size="small"
          style="width: 180px"
        >
          <el-option
            v-for="option in typeOptions"
            :key="option.value"
            :label="option.label"
            :value="option.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="直播间id" prop="roomId">
        <el-input
          v-model="queryParams.roomId"
          placeholder="请输入直播间id"
          clearable
          size="small"
          style="width: 180px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="发红包uid" prop="uid">
        <el-input
          v-model="queryParams.uid"
          placeholder="请输入发红包用户uid"
          clearable
          size="small"
          style="width: 180px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="是否抢完" prop="isFinish">
        <el-select
          v-model="queryParams.isFinish"
          placeholder="红包是否被抢光"
          clearable
          size="small"
          style="width: 180px"
        >
          <el-option
            v-for="item in isFinishOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="红包最小金额" prop="sendMinMoney">
        <el-input v-model.number="queryParams.sendMinMoney" max="4999" :step="1" style="width: 240px"></el-input>
      </el-form-item>

      <el-form-item label="红包最大金额" prop="sendMaxMoney">
        <el-input v-model.number="queryParams.sendMaxMoney" max="5000" :step="1" style="width: 240px"></el-input>
      </el-form-item>

      <el-form-item label="扣税最低金额" prop="taxMinMoney">
        <el-input v-model.number="queryParams.taxMinMoney" max="1500" :step="1" style="width: 240px"></el-input>
      </el-form-item>


      <el-form-item label="红包时间">
        <el-date-picker
          v-model="queryParams.dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordList" @selection-change="handleSelectionChange">
      <el-table-column label="红包id" prop="id" width="100" />
      <el-table-column label="红包类型" prop="type" :show-overflow-tooltip="true" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.type === 1">随机红包</span>
          <span v-if="scope.row.type === 2">平均红包</span>
          <span v-if="scope.row.type === 3">系统红包</span>
        </template>
      </el-table-column>
      <el-table-column label="红包金额" prop="sendMoney" width="120">
        <template slot-scope="scope">
          <span v-text="scope.row.sendMoney / 100"></span>
        </template>
      </el-table-column>
      <el-table-column label="扣税金额" prop="taxMoney" width="120">
        <template slot-scope="scope">
          <span v-text="scope.row.taxMoney / 100"></span>
        </template>
      </el-table-column>
      <el-table-column label="红包数量" prop="num" width="100" />
      <el-table-column label="已领取数量" prop="gainNum" width="100" />
      <el-table-column label="已领取金额" prop="gainMoney" width="100">
        <template slot-scope="scope">
          <span v-text="scope.row.gainMoney / 100"></span>
        </template>
      </el-table-column>
      <el-table-column label="直播间id" prop="roomId" width="100" />
      <el-table-column label="用户uid" prop="uid" width="100" />
      <el-table-column label="状态" prop="status" :show-overflow-tooltip="true" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.status === 0">发放中..</span>
          <span v-if="scope.row.status === 1">已抢光</span>
          <span v-if="scope.row.status === 2">已结束，未抢光</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listRecord} from "@/api/activity/red/record";

export default {
  name: "RedPacketRecord",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        // 日期范围
        dateRange: [],
        pageNum: 1,
        pageSize: 10,
        type:'',
        roomId:'',
        uid:'',
        isFinish:undefined,
        sendMinMoney:undefined,
        sendMaxMoney:undefined,
        sendMoney:undefined,
        gainMoney:undefined,
        taxMinMoney:undefined,
        taxMoney:undefined
      },
      // 表单参数
      form: {},
      typeOptions:[
        {
          value: 1,
          label: "随机红包"
        },
        {
          value: 2,
          label: "平均红包"
        },
        {
          value: 3,
          label: "系统红包"
        }
      ],
      isFinishOptions:[
        {
          value: 1,
          label: "是"
        },
        {
          value: 0,
          label: "否"
        }
      ]
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询条件列表 */
    getList() {
      this.loading = true;
      this.addDateRange2(this.queryParams,this.queryParams.dateRange)
      listRecord(this.queryParams).then(
        response => {
          this.recordList = response.records;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        type: undefined,
        parameter: undefined,
        lowerLimit: undefined,
        description: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
